﻿Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols

<WebService(Namespace:="http://www.resamu.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class ResaMessage
    Inherits System.Web.Services.WebService

    <WebMethod()> _
   Public Function NewMessageSystem(ByVal idresamu As String, ByVal idequipe As String, ByVal numref As String, ByVal type As String) As String
        Dim message As String
        Dim id As System.Guid = System.Guid.NewGuid
        Dim ResaLog As New ResaLog.logsurvey
        ResaLog.Url = Application("ResaLog")
        ResaLog.Timeout = 60000
        Dim dbMessage As New DataSetMessageTableAdapters.EcouteTableAdapter
        Try
            dbMessage.Insert(id.ToString, idresamu, idequipe, type, numref)
            message = "NEWMESSAGESYSTEMOK"
        Catch ex As Exception
            message = "ERROR/" + ex.Message
        End Try
        ResaLog.NewLog(idresamu, idequipe, "system", "NewMessageSystem", message)
        Return message
    End Function
    <WebMethod()> _
    Public Function NewMessageTexte(ByVal idresamu As String, ByVal idequipe As String, ByVal idpers As String, _
    ByVal numref As String, ByVal texte As String, ByVal pwd As String, ByVal iduser As String) As String
        Dim message As String
        Dim id As System.Guid = System.Guid.NewGuid
        Dim dbEcoute As New DataSetMessageTableAdapters.EcouteTableAdapter
        Dim dbTexte As New DataSetMessageTableAdapters.TexteTableAdapter
        Dim ResaLog As New ResaLog.logsurvey
        ResaLog.Url = Application("ResaLog")
        ResaLog.Timeout = 60000
        Dim Securite As New Identification.user
        Dim Identite As String()
        Securite.Url = Application("Identification")
        Securite.Timeout = 60000
        Try
            Identite = Securite.Identification(iduser, pwd, idpers).Split("/")
            If Identite(0) = "IDOK" Then
                dbEcoute.Insert(id.ToString, idresamu, idequipe, "TEXTE", numref)
                dbTexte.Insert(texte, id.ToString)
                message = "NEWMESSAGEOK"
            Else
                message = "ERROR/INTRUSION"
            End If
        Catch ex As Exception
            message = "ERROR/" + ex.Message
        End Try
        ResaLog.NewLog(idresamu, idequipe, idpers, "NewMessageTexte", message)
        Return message

    End Function
    <WebMethod()> _
    Public Function RegarderMessage(ByVal idresamu As String, ByVal idequipe As String, ByVal pwd As String, ByVal idpers As String) As System.Xml.XmlDocument
        Dim XmlMessage As New System.Xml.XmlDocument
        Dim dbData As New DataSetMessageTableAdapters.EcouteTableAdapter
        Dim data As New DataSetMessage.EcouteDataTable
        Dim ResaLog As New ResaLog.logsurvey
        ResaLog.Url = Application("ResaLog")
        ResaLog.Timeout = 60000
        Dim Securite As New Identification.user
        Dim Identite As String()
        Securite.Url = Application("Identification")
        Securite.Timeout = 60000
        Dim message As String
        Try
            Identite = Securite.Identification(idresamu, pwd, idpers).Split("/")
            If Identite(0) = "IDOK" Then
                data = dbData.GetDataByID(idresamu, idequipe)
                data.WriteXml(Server.MapPath("Message" + idresamu + idequipe + ".xml"))
                XmlMessage.Load(Server.MapPath("Message" + idresamu + idequipe + ".xml"))
                'Dim i As Integer
                'For i = 0 To (data.Rows.Count - 1)
                '    dbData.DeleteQueryById(data(i).id_message)
                'Next
                message = "LECTUREOK"
            Else
                XmlMessage.LoadXml("<MESSAGE>ERROR/INTRUSION</MESSAGE>")
                message = "ERROR/INTRUSION"
            End If
        Catch ex As Exception
            XmlMessage.LoadXml("<MESSAGE>ERROR/" + ex.Message + "</MESSAGE>")
            message = "ERROR/" + ex.Message
        End Try
        ResaLog.NewLog(idresamu, idequipe, idpers, "RegarderMessage", message)
        Return XmlMessage

    End Function
    <WebMethod()> _
    Public Function TelechargerTexte(ByVal idresamu As String, ByVal pwd As String, ByVal idpers As String, ByVal idtexte As String) As String
        Dim message As String
        Dim dbTexte As New DataSetMessageTableAdapters.TexteTableAdapter
        Dim data As New DataSetMessage.TexteDataTable
        Dim Identite As String()
        Dim Securite As New Identification.user
        Securite.Url = Application("Identification")
        Securite.Timeout = 60000
        Dim ResaLog As New ResaLog.logsurvey
        ResaLog.Url = Application("ResaLog")
        ResaLog.Timeout = 60000
        Try
            Identite = Securite.Identification(idresamu, pwd, idpers).Split("/")
            If Identite(0) = "IDOK" Then
                data = dbTexte.GetDataById(idtexte)
                message = data(0).message_texte
            Else
                message = "ERROR/INTRUSION"
            End If
        Catch ex As Exception
            message = "ERROR/" + ex.Message
        End Try
        ResaLog.NewLog(idresamu, "system", idpers, "TelechargerTexte", message)
        Return message
    End Function
    <WebMethod()> _
       Public Function Test(ByVal idresamu As String, ByVal pwd As String, ByVal idpers As String) As String
        Dim message As String
        Dim ResaUser As New Identification.user
        ResaUser.Timeout = -1
        ResaUser.Url = Application("Identification")
        message = ResaUser.Identification(idresamu, pwd, idpers)
        Dim LOG As New ResaLog.logsurvey
        LOG.Timeout = 60000
        LOG.Url = Application("ResaLog")
        LOG.NewLog(idresamu, "WSRSMSG", idpers, "TEST", message)
        Return message
    End Function
    '<WebMethod()> _
    'Public Function GetLastList(ByVal idresamu As String, ByVal idteam As String, ByVal pwd As String) As System.Xml.XmlDocument
    '    Dim listmessage As New System.Xml.XmlDocument
    '    Dim ResaLog As New ResaLog.logsurvey
    '    ResaLog.Url = Application("ResaLog")
    '    ResaLog.Timeout = 60000
    '    Dim Securite As New Identification.user
    '    Dim Identite As String()
    '    Securite.Url = Application("Identification")
    '    Securite.Timeout = 60000
    '    Dim message As String
    '    Try
    '        Identite = Securite.Identification(idresamu, pwd).Split("/")
    '        If Identite(0) = "IDOK" Then
    '            listmessage.Load(Server.MapPath("Message" + idresamu + idteam + ".xml"))
    '            message = "LECTUREOK"
    '        Else
    '            listmessage.LoadXml("<MESSAGE>ERROR/INTRUSION</MESSAGE>")
    '            message = "ERROR/INTRUSION"
    '        End If
    '    Catch ex As Exception
    '        listmessage.LoadXml("<MESSAGE>ERROR/" + ex.Message + "</MESSAGE>")
    '        message = "ERROR/" + ex.Message
    '    End Try
    '    ResaLog.NewLog(idresamu, idteam, "system", "GetLastList", message)
    '    Return listmessage
    'End Function
    <WebMethod()> _
    Public Function ARMessage(ByVal idresamu As String, ByVal idteam As String, ByVal pwd As String, ByVal idpers As String, ByVal refmessage As String) As String
        Dim dbData As New DataSetMessageTableAdapters.EcouteTableAdapter
        Dim ResaLog As New ResaLog.logsurvey
        ResaLog.Url = Application("ResaLog")
        ResaLog.Timeout = 60000
        Dim Securite As New Identification.user
        Dim Identite As String()
        Securite.Url = Application("Identification")
        Securite.Timeout = 60000
        Dim message As String
        Try
            Identite = Securite.Identification(idresamu, pwd, idpers).Split("/")
            If Identite(0) = "IDOK" Then
                dbData.DeleteQueryById(refmessage)
                message = "AROK"
            Else
                message = "ERROR/INTRUSION"
            End If
        Catch ex As Exception
            message = "ERROR/" + ex.Message
        End Try
        Try
            ResaLog.NewLog(idresamu, idteam, idpers, "ARMessage" + refmessage, message)
        Catch ex As Exception

        End Try
        Return message
    End Function
End Class
